    //
//  AboutController.m
//  MClient
//
//  Created by Wang Fei on 10-8-5.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "AboutController.h"
#import "MClientAppDelegate.h"
#import "TableCellType1.h"

@implementation AboutController

- (int)identiferId {
	return 0;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];
	
	self.title = @"关于";
	
	self.tableview.backgroundColor = [UIColor clearColor];
	self.addHelpButton = YES;
	self.helpUrl = @"/iphone/help/chapter02-03.html";
	
	 // 动作按钮“清除流量统计”============================
	[self rightBarButton:@"清空流量统计" withStyle:UIBarButtonItemStyleDone selector:@selector(selectOk:)];
}


- (void)dealloc {
    [super dealloc];
}

#pragma mark ----------UITableView----------
//Section数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 2;
}

//TableView的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	if (section == 0) {
		return 2;
	} else {
		return 4;
	}
}

- (NSString*)getValueText:(int)flowvalue
{
	if (flowvalue < 1024) {
		return [NSString stringWithFormat:@"%dB", flowvalue]; 
	} else if (flowvalue < 1048576) {
		return [NSString stringWithFormat:@"%0.2fK", (flowvalue / 1024.0)]; 
	} else if (flowvalue < 1073741824) {
		return [NSString stringWithFormat:@"%0.2fM", (flowvalue / 1048576.0)];
	} else {
		return @"数据过大，请清空！";
	}
}
//初始化TableVie根据参数和数据绘制每一行以及填充数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	AboutTableCell *cell = (AboutTableCell*)[super tableCell:tableView withClass:[AboutTableCell class] withIdentifier:@"AboutTableCell"];
	cell.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
	if (indexPath.section==0) {
		if (indexPath.row == 0) {
			[cell show:@"软件名称：" withContent:[[MClientAppDelegate getInfoDictionary] objectForKey:@"CFBundleDisplayName"]];
		} else {
			[cell show:@"版本号：" withContent:[[MClientAppDelegate getInfoDictionary] objectForKey:@"CFBundleVersion"]];
		}
	} else {
		if (indexPath.row == 0) {
			[cell show:@"本次发送流量：" withContent:[self getValueText:self.userDefaults.currentReq]];
		} else if (indexPath.row == 1){
			[cell show:@"本次接收流量：" withContent:[self getValueText:self.userDefaults.currentRes]];
		} else if (indexPath.row == 2){
			[cell show:@"发送流量总计：" withContent:[self getValueText:self.userDefaults.totalReq]];
		} else {
			[cell show:@"接收流量总计：" withContent:[self getValueText:self.userDefaults.totalRes]];
		}
	}
	return cell;	
}

#pragma mark ---- 按钮事件处理方法 ----
- (void) selectOk: (id) sender {
	self.userDefaults.currentReq = 0;
	self.userDefaults.currentRes = 0;
	self.userDefaults.totalReq = 0;
	self.userDefaults.totalRes = 0;
	
	[self reloadData];
}


@end
